package com.dongdongshop.service.impl;

import com.dongdongshop.mapper.TbContentCategoryMapper;
import com.dongdongshop.mapper.TbContentMapper;
import com.dongdongshop.pojo.PageResult;
import com.dongdongshop.pojo.TbContent;
import com.dongdongshop.pojo.TbContentExample;
import com.dongdongshop.service.TbContentService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@DubboService
public class TbContentServiceImpl implements TbContentService {

    //注入mapper
    @Autowired
    private TbContentMapper tbContentMapper;

    //查询全部广告列表(要求分页)
    @Override
    public PageResult<TbContent> TbContentshowall(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<TbContent> tbContents = tbContentMapper.selectByExample(null);
        PageInfo<TbContent> info = new PageInfo<>(tbContents);
        return new PageResult<TbContent>(pageNum,pageSize,info.getTotal(),info.getList(),info.getPages());
    }

    //添加广告
    @Override
    public void addTbContent(TbContent tbContent) {
        tbContentMapper.insertSelective(tbContent);
    }

    //回显单个广告分类数据
    @Override
    public TbContent showecho(Long id) {
        return tbContentMapper.selectByPrimaryKey(id);
    }

    @Override
    public void updateTbContent(TbContent tbBrand) {
        tbContentMapper.updateByPrimaryKeySelective(tbBrand);
    }

    //删除单个数据
    @Override
    public void deleteTbContent(Long id) {
        tbContentMapper.deleteByPrimaryKey(id);
    }

    //删除多个数据
    @Override
    public void deleteallTbContent(List<Long> ids) {
        TbContentExample te = new TbContentExample();
        TbContentExample.Criteria criteria = te.createCriteria();
        criteria.andIdIn(ids);
        tbContentMapper.deleteByExample(te);
    }

    //查询数据(按照分类,降序,有效)
    @Override
    public List<TbContent> showTbContentbycategoryId(Integer categoryId) {
        return tbContentMapper.showTbContentbycategoryId(categoryId);
    }
}
